﻿using System;

using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;
using PasswordSafe.Classes;

namespace PasswordSafe
{
    public class WelcomeScreen:FluidPanel
    {
        protected override void InitControl()
        {
            base.InitControl();
            Bounds = new Rectangle(0,0,240,300);
            BackColor = Color.LightSteelBlue;
            this.GradientFill = true;
            GradientFillOffset = 30;
            ForeColor = Color.White;

            FluidLabel h1 = new FluidLabel("Welcome", 0, 0, 240, 40);
            h1.ShadowColor = Color.Black;
            h1.ForeColor = Color.White;
            h1.Alignment = StringAlignment.Center;
            h1.LineAlignment = StringAlignment.Center;
            h1.Font = new Font(FontFamily.GenericSansSerif,12f,FontStyle.Bold);
            h1.Anchor = AnchorTLR;
            Controls.Add(h1);

            string infoText = "This is the first time you started PasswordSafe and an empty database named passwords.pws is automatically" +
                " generated in the 'MyDevice' folder of your Windows Mobile.\n\n" +
                "As next step, in the Login Screen, you need to give your database a password by tapping the 'Change Password' button.\n" +
                "Notice that your current password is empty.\n\n" +
                "You should backup your database from time to time. If you remove your password.xml, this welcome screen comes again " +
                "to create a new database.\n\n" +
                "If you don't choose a password, your database is readable as xml file.\n";

            FluidLabel infoLabel = new FluidLabel(infoText, 3, 40, 240-6, 220);
            infoLabel.ForeColor = Color.Black;
            infoLabel.Font = new Font(FontFamily.GenericSansSerif, 8f, FontStyle.Regular);
            infoLabel.Alignment = StringAlignment.Near;
            infoLabel.LineAlignment = StringAlignment.Near;
            infoLabel.Format.FormatFlags = 0;
            infoLabel.Anchor = AnchorTLR;
            Controls.Add(infoLabel);

            FluidButton okBtn = new FluidButton("Start", 70, 300 - 40, 100, 32);
            this.okBtn = okBtn;
            okBtn.BackColor = Color.LightSlateGray;           
            okBtn.Click += new EventHandler(okBtn_Click);
            okBtn.ForeColor = Color.White;
            okBtn.Anchor = AnchorBL;
            Controls.Add(okBtn);

        }

        void okBtn_Click(object sender, EventArgs e)
        {
           
            DataReader.CreateDatabase();
            Close();
            if (Continue != null) Continue(this, e);
        }

        private FluidButton okBtn = new FluidButton();

        protected override void OnSizeChanged(Size oldSize, Size newSize)
        {
            base.OnSizeChanged(oldSize, newSize);
            int w = this.Width;
            okBtn.Left = (w - okBtn.Width) / 2;
        }

        public event EventHandler Continue;
    }
}
